package com.lwd.util;

import com.raycloud.erp.performance.model.constant.AppConstants;
import com.raycloud.erp.performance.util.DateUtil;

import java.util.Calendar;
import java.util.Date;

/**
 * @author devil
 * @date 2018/9/12
 */
public class PerformanceDateUtil {

    /** 时间为空，或者是默认时间2000-01-01 00:00:00 */
    public static boolean isNullOrDefaultTimestamp(Date date) {
        return date == null || date.getTime() == AppConstants.DEFAULT_TIMESTAMP_DATE.getTime();
    }

    /**
     * @param dateSrc 使用该Date的年月日
     * @param timeSrc 使用该Date的时分秒
     */
    public static Date copyDate(Date dateSrc, Date timeSrc) {
        Calendar src = Calendar.getInstance();
        src.setTime(dateSrc);

        Calendar dst = Calendar.getInstance();
        dst.setTime(timeSrc);

        dst.set(Calendar.YEAR, src.get(Calendar.YEAR));
        dst.set(Calendar.MONTH, src.get(Calendar.MONTH));
        dst.set(Calendar.DAY_OF_MONTH, src.get(Calendar.DAY_OF_MONTH));

        return dst.getTime();
    }

    public static void main(String[] args) {
        System.out.println(DateUtil.formatYMD_HMS(copyDate(DateUtil.parseYMD_HMS("2019-03-24 13:13:12"), DateUtil.parseYMD_HMS("1970-01-23 12:12:12"))));
    }



    public static Date addYear(Date date, int interval) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR, interval);
        return calendar.getTime();
    }


    public static boolean isLastDayOfMonth(Date date) {
        Date nextDay = DateUtil.addDay(date, 1);
        return !DateUtil.isSameMonth(date, nextDay);
    }
}
